package phoenix.web.page_objects.features;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.PageBaseWebExt;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.web.locators.base.features.MenuLocatorsBase;

/**
 * Created by AlexGolovko on 13.11.2014.
 */
public class MenuPage extends PageBaseWebExt
{
	/**
	 * Initializes PageBaseWebExt
	 * @param p_manager PhoenixManager instance
	 */
	public MenuPage(PhoenixManager p_manager)
	{
		super(p_manager);
	}

	public MenuLocatorsBase elements()
	{
		switch (manager.testModel().getSiteName())
		{
			case ConfigExt.SITE_ID_CLICKANDFLIRT:
			{
				return new phoenix.web.locators.clickandflirt.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_LOCALSGOWILD:
			{
				return new phoenix.web.locators.localsgowild.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_EBONYFLIRT:
			{
				return new phoenix.web.locators.ebonyflirt.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_CHEECKYLOVERS:
			{
				return new phoenix.web.locators.cheekylovers.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_WILDBUDDIES:
			{
				return new phoenix.web.locators.wildbuddies.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_FLIRT:
			{
				return new phoenix.web.locators.flirt.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_FOREIGNGIRLFRIEND:
			{
				return new phoenix.web.locators.foreigngirlfriend.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_BENAUGHTY:
			{
				return new phoenix.web.locators.benaughty.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_NAUGHTYFEVER:
			{
				return new phoenix.web.locators.naughtyfever.features.MenuLocators();
			}
			case ConfigExt.SITE_ID_MATUREDATING:
			{
				return new phoenix.web.locators.maturedating.features.MenuLocators();
			}
			default:
			{
				return new phoenix.web.locators.benaughty.features.MenuLocators();
			}
		}
	}

	/**
	 * FLIRT
	 * @param p_typeOfMode
	 */
	public void setNaughtyMode(Integer p_typeOfMode)
	{
		this.clickNaughtyWidget();
		wd().wait(1);
		if (this.isNaughtyWidgetOpenned())
		{

			try
			{
				switch (p_typeOfMode)
				{
					case 1:
						this.clickNaughtyNormal();
					case 2:
						this.clickNaughtySexy();
					case 3:
						this.clickNaughtyHot();
				}

			}
			catch (Exception p)
			{
				log().warn("Status " + p_typeOfMode + " already set ?" + p.toString());
			}

			wd().wait(5);

			if (this.isNaughtyWidgetOpenned())
			{
				this.clickNaughtyWidget();
				wd().wait(1);
			}

			if (this.isNaughtyPopUpDisplayed())
			{
				this.clickNaughtyPopUpSubmit();
				wd().wait(1);
			}
			else
			{
				log().warn("Cannot find naughty pop-up window");
			}
		}
		else
		{
			log().warn("Cannot find naughty widget window");
		}
	}

	/**
	 * Main menu
	 */
	public void clickMainMenu()
	{
		wd().waitForPresence(elements().btnUserAvatar, "Block User avatar");
		wd().click(elements().btnUserAvatar);
	}

	public boolean isMainMenuPresent()
	{
		return wd().isElementDisplayed(elements().blockUserMenu);
	}

	public void clickMyAccount()
	{
		wd().waitForPresence(elements().btnMySettings, "MyAccount button");
		wd().click(elements().btnMySettings);
	}

	public void clickMyProfile()
	{
		wd().waitForPresence(elements().btnMyProfile, "MyProfile button");
		wd().click(elements().btnMyProfile);
	}

	public void clickBlocked()
	{
		wd().waitForPresence(elements().btnBlocked, "Blocked button");
		wd().click(elements().btnBlocked);
	}

	public void clickContactUs()
	{
		wd().waitForPresence(elements().btnContactUs, "ContactUs button");
		wd().click(elements().btnContactUs);
	}

	public void clickLogout()
	{
		wd().waitForPresence(elements().btnLogout, "Logout button");
		wd().click(elements().btnLogout);
	}

	/**
	 * Search Menu
	 */
	public void clickSearchOnline()
	{
		wd().waitForVisibility(elements().btnSearchOnline, "Link 'Search Online'");
		wd().click(elements().btnSearchOnline);
	}

	public void clickPhotoQuality()
	{
		wd().waitForVisibility(elements().btnSearchNear, "Link 'Photo Quality'");
		wd().click(elements().btnSearchNear);
	}

	public void clickNewMembers()
	{
		wd().waitForVisibility(elements().btnSearchRecently, "Link 'New Members'");
		wd().click(elements().btnSearchRecently);
	}

	public void clickSearchNavigationMenu()
	{
		wd().waitForVisibility(elements().btnOpenSearchDropdown, "Button 'Search dropdown'");
		wd().click(elements().btnOpenSearchDropdown);
	}

	/**
	 * Activity Menu
	 */
	public void clickViews()
	{
		wd().waitForPresence(elements().linkActivityBrowsedMe, "Link 'Views'");
		wd().click(elements().linkActivityBrowsedMe);
	}

	public void clickWinks()
	{
		wd().waitForPresence(elements().linkActivityWinkedMe, "Link 'Winks'");
		wd().click(elements().linkActivityWinkedMe);
	}

	public void clickFeed()
	{
		wd().waitForPresence(elements().linkActivityFeed, "Link 'Feed'");
		wd().click(elements().linkActivityFeed);
	}

	public void clickSmsChat()
	{
		wd().waitForPresence(elements().linkActivitySMSChat, "Link 'SmsChat'");
		wd().click(elements().linkActivitySMSChat);
	}

	public void clickMessenger()
	{
		wd().waitForPresence(elements().linkActivityMessenger, "Link 'Messenger'");
		wd().click(elements().linkActivityMessenger);
	}

	public void clickFriends()
	{
		wd().waitForPresence(elements().linkActivityFriends, "Link 'Friends'");
		wd().click(elements().linkActivityFriends);
	}

	public void clickActivityNavigationMenu()
	{
		wd().waitForPresence(elements().linkFeedDropdownMenu, "Link 'Feed dropdown'");
		wd().click(elements().linkFeedDropdownMenu);
	}

	/**
	 * Top menu
	 */
	public void waitForPageLoad()
	{
		wd().waitForPresence(elements().blockTopMenu, "Block 'Top Menu'");
	}

	public void clickTopMenuSearch()
	{
		wd().waitForPresence(elements().linkTopSearch, "Link 'Top Search'");
		wd().click(elements().linkTopSearch);
	}

	public void clickTopMenuBrowsedMe()
	{
		wd().waitForPresence(elements().linkTopBrowsedMe, "Link 'Browsed Me'");
		wd().click(elements().linkTopBrowsedMe);
	}

	public boolean isActivityHistoryDisplayed()
	{
		return wd().isElementPresent(elements().blockDropDownMenu);
	}

	public void clickTopMenuMyFriends()
	{
		wd().waitForPresence(elements().linkTopMyFriends, "Link 'Top My Friends'");
		wd().click(elements().linkTopMyFriends);
	}

	public void clickTopMenuMessagedMe()
	{
		wd().wait(2); // Js load
		wd().waitForPresence(elements().linkTopMessagedMe, "Messenger button at top menu");
		wd().click(elements().linkTopMessagedMe);
	}

	public void clickCommunicationPopupDropMenu()
	{
		wd().waitForPresence(elements().linkDropDownCommunicationPopup, "Link 'Drop down communication popup'");
		wd().click(elements().linkDropDownCommunicationPopup);
	}

	public void clickTopMenuWinkedMe()
	{
		wd().waitForPresence(elements().linkTopWinkedMe, "Winked Me button");
		wd().click(elements().linkTopWinkedMe);
	}

	public void clickTopMenuFeed()
	{
		wd().waitForPresence(elements().linkTopFeed, "Link 'Top Feed'");
		wd().click(elements().linkTopFeed);
	}

	public void clickTopMenuChatRooms()
	{
		wd().waitForPresence(elements().linkTopChatRoom, "Link 'Top Chat Room'");
		wd().click(elements().linkTopChatRoom);
	}

	public void clickTopMenuSMSChat()
	{
		wd().waitForVisibility(elements().linkSMSChat, "Sms chat block");
		wd().click(elements().linkSMSChat);
	}

	public void clickAcitivityNavigation()
	{
		wd().waitForVisibility(elements().btnNavigationList, "Block 'Navigation List'");
		wd().wait(2);
		wd().click(elements().btnNavigationList);
	}

	public boolean isSeeAllDisplayed()
	{
		return wd().isElementDisplayed(elements().btnSeeAll);
	}

	public boolean isSeeAllPresent()
	{
		return wd().isElementPresent(elements().btnSeeAll);
	}

	public void clickSeeAll()
	{
		wd().waitForPresence(elements().btnSeeAll, "See all button");
		wd().click(elements().btnSeeAll);
	}

	public boolean isAcitivityNavigationDisplayed()
	{
		wd().waitForPresence(elements().blockDropDownMenu, "Block Drop down menu active");
		return wd().isElementDisplayed(elements().blockDropDownMenu);
	}

	public void clickAcitivityNavigationClose()
	{
		wd().waitForPresence(elements().linkActivityClose, "Close Activity navigation bar");
		wd().click(elements().linkActivityClose);
	}

	public void clickTopMenuActivity()
	{
		wd().waitForPresence(elements().linkTopActivity, "Top menu button 'Views'");
		wd().click(elements().linkTopActivity);
	}

	public boolean isFeedDropDownDisplayed()
	{
		return wd().isElementDisplayed(elements().blockDropDownMenuFeed);
	}

	public void clickFeedDropDownLink()
	{
		wd().waitForPresence(elements().btnOpenFeed, "Drop down button 'Open feed'");
		wd().click(elements().btnOpenFeed);
	}

	public boolean isActivityDropDownDisplayed()
	{
		return wd().isElementDisplayed(elements().blockDropDownMenuActivity);
	}

	public void clickActivityDropDownLink()
	{
		wd().waitForPresence(elements().btnOpenActivity, "Drop down button 'Open activity'");
		wd().click(elements().btnOpenActivity);
	}

	public boolean isViewsDropDownDisplayed()
	{
		return wd().isElementDisplayed(elements().blockDropDownMenuViews);
	}

	public void clickViewsDropDownLink()
	{
		wd().waitForPresence(elements().btnOpenViews, "Drop down button 'Open views'");
		wd().click(elements().btnOpenViews);
	}

	public boolean isWinksDropDownDisplayed()
	{
		return wd().isElementDisplayed(elements().blockDropDownMenuWinks);
	}

	public void clickWinksDropDownLink()
	{
		wd().waitForPresence(elements().btnOpenWinks, "Drop down button 'Open winks'");
		wd().click(elements().btnOpenWinks);
	}

	public boolean isFriendsDropDownDisplayed()
	{
		return wd().isElementDisplayed(elements().blockDropDownMenuFriends);
	}

	public void clickFriendsDropDownLink()
	{
		wd().waitForPresence(elements().btnOpenFriends, "Drop down button 'Open friends'");
		wd().click(elements().btnOpenFriends);
	}

	public boolean isTopFeedCounterActivePresent()
	{
		return wd().isElementPresent(elements().linkTopFeedCounterActive);
	}

	public void clickTopFeedCounterActive()
	{
		wd().waitForPresence(elements().linkTopFeedCounterActive, "Link 'Top feed counter active'");
		wd().click(elements().linkTopFeedCounterActive);
	}

	public boolean isTopMyFriendsCounterActivePresent()
	{
		return wd().isElementPresent(elements().linkTopMyFriendsCounterActive);
	}

	public void clickTopMyFriendsCounterActive()
	{
		wd().waitForPresence(elements().linkTopMyFriendsCounterActive, "Link 'Top my friends counter active'");
		wd().click(elements().linkTopMyFriendsCounterActive);
	}

	public boolean isTopWinkedMeCounterActivePresent()
	{
		return wd().isElementPresent(elements().linkTopWinkedMeCounterActive);
	}

	public void clickTopWinkedMeCounterActive()
	{
		wd().waitForPresence(elements().linkTopWinkedMeCounterActive, "Link 'Top winked me counter active'");
		wd().click(elements().linkTopWinkedMeCounterActive);
	}

	public boolean isTopBrowsedMeCounterActivePresent()
	{
		return wd().isElementPresent(elements().linkTopBrowsedMeCounterActive);
	}

	public void clickTopBrowsedMeCounterActiveActive()
	{
		wd().waitForPresence(elements().linkTopBrowsedMeCounterActive, "Link 'Top browsed me counter active'");
		wd().click(elements().linkTopBrowsedMeCounterActive);
	}

	/**
	 * Left bar menu
	 */
	public void clickLeftBarFriends()
	{
		wd().waitForPresence(elements().btnNavFavorits, "Favorites button");
		wd().click(elements().btnNavFavorits);
	}

	public void clickLeftBarActivity()
	{
		wd().waitForPresence(elements().btnNavActivity, "Activity button");
		wd().click(elements().btnNavActivity);
	}

	public void clickLeftBarFeed()
	{
		wd().waitForPresence(elements().btnNavFeed, "Feed button");
		wd().click(elements().btnNavFeed);
	}

	public void clickLeftBarChatRooms()
	{
		wd().waitForPresence(elements().btnNavChat, "Chat button");
		wd().click(elements().btnNavChat);
	}

	public void clickLeftBarForum()
	{
		wd().waitForPresence(elements().btnNavForum, "Forum button");
		wd().click(elements().btnNavForum);
	}

	/**
	 * Naughty mode Flirt related
	 */
	public void clickNaughtyWidget()
	{
		wd().waitForPresence(elements().btnNaughtyMode, "Naughty widget at top");
		wd().click(elements().btnNaughtyMode);
	}

	public boolean isNaughtyWidgetOpenned()
	{
		return wd().isElementPresent(elements().blockNaughtyMode);
	}

	public void clickNaughtyNormal()
	{
		wd().waitForPresence(elements().btnNaughtyNormal, "Button normal");
		wd().click(elements().btnNaughtyNormal);
	}

	public void clickNaughtySexy()
	{
		wd().waitForPresence(elements().btnNaughtySexy, "Button sexy");
		wd().click(elements().btnNaughtySexy);
	}

	public void clickNaughtyHot()
	{
		wd().waitForPresence(elements().btnNaughtyHot, "Button hot");
		wd().click(elements().btnNaughtyHot);
	}

	public boolean isNaughtyPopUpDisplayed()
	{
		return wd().isElementDisplayed(elements().blockNaughtyPopUpConfirm);
	}

	public void clickNaughtyPopUpSubmit()
	{
		wd().waitForPresence(elements().btnNaughtyPopUpSubmit, "Naughty pop-up submit");
		wd().click(elements().btnNaughtyPopUpSubmit);
	}

	/**
	 * MD related
	 */
	public void clickSearchSubmit()
	{
		wd().waitForPresence(elements().btnSearchSubmit, "Search submit");
		wd().click(elements().btnSearchSubmit);
	}
}
